package com.hyz.reggie.controller;

import com.hyz.reggie.pojo.R;
import com.hyz.reggie.pojo.ShoppingCart;
import com.hyz.reggie.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/shoppingCart")
public class CartController {
    @Autowired
    private CartService service;

    @PostMapping("/add")
    public R add(@RequestBody ShoppingCart shoppingCart) {
        ShoppingCart cart = service.add(shoppingCart);
        return R.success(cart);
    }

    @GetMapping("/list")
    public R getList() {
        List<ShoppingCart> list = service.getList();
        return R.success(list);
    }

    @PostMapping("/sub")
    public R sub(@RequestBody ShoppingCart shoppingCart) {

        return service.sub(shoppingCart);
    }

    @DeleteMapping("/clean")
    public R clean() {
        service.clean();
        return R.success("清空成功~");
    }
}
